<?php

class CourseBean implements IDBBean {
	
	public $id;
	public $courseName;
	public $courseType;
	public $department;
	public $teacherType;
	public $teacherName;
	public $organization;
	public $jobTitle;
	public $credential;
	public $courseBegin;
	public $courseEnd;
	public $time;
	public $unit;
	public $salary;
	public $salaryStandard;
	public $new = true;
	public $approval = false;
	public $summaryTitle;
	public $summary;
	public static $_COURSE = 1;
	public static $_LECTURE = 2;
	public static $YUAN_PER_HOUR = 0;
	public static $YUAN_PER_MONTH = 1;
	public static $DOLLARS_PER_HOUR = 2;
	public static $DOLLARS_PER_MONTH = 3;
	public static $YUAN_PER_TIME = 4;
	public static $DOLLARS_PER_TIME = 5;
	public static $standardAttrs = array ("元/学时", "元/月", "美元/学时", "美元/月", "元/场", "美元/场" );
	public function __construct($fields = array()) {
		foreach ( $fields as $key => $value ) {
			$this->$key = $value;
		}
	
		//$courseName = $fields["courseName"];
	//$department = $fields["department"];
	//$teacherType = $fields["teacherType"];
	//$teacherName = $fields["teacherName"];
	//$organization = $fields["organization"];
	//$jobTitle = $fields["jobTitile"];
	//$credential = $fields["credential"];
	//$courseBegin = $fields["courseBegin"];
	//$courseEnd = $fields["courseEnd"];
	//$salary = $fields["salary"];
	//$time = $fields["time"];
	//$unit = $fields["unit"];
	// 		$this->courseType = $type;
	//if(!isset($fields["new"]))
	//	$new = true;
	//if(!isset($fields["approval"])
	//	$this->approval = false;
	}
	
	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels() {
		return array ('courseName' => '课程名称' );
	}
	
	/**
	 * @return the $id
	 */
	public function getId() {
		return $this->id;
	}
	
	/**
	 * @param field_type $id
	 */
	public function setId($id) {
		$this->id = $id;
	}
	
	/**
	 * @return the $courseType
	 */
	public function getCourseType() {
		return $this->courseType;
	}
	
	/**
	 * @param field_type $courseType
	 */
	public function setCourseType($courseType) {
		$this->courseType = $courseType;
	}
	
	/**
	 * @return the $courseName
	 */
	public function getCourseName() {
		return $this->courseName;
	}
	
	/**
	 * @return the $department
	 */
	public function getDepartment() {
		return $this->department;
	}
	
	/**
	 * @return the $teacherType
	 */
	public function getTeacherType() {
		return $this->teacherType;
	}
	
	/**
	 * @return the $teacherName
	 */
	public function getTeacherName() {
		return $this->teacherName;
	}
	
	/**
	 * @return the $organization
	 */
	public function getOrganization() {
		return $this->organization;
	}
	
	/**
	 * @return the $jobTitle
	 */
	public function getJobTitle() {
		return $this->jobTitle;
	}
	
	/**
	 * @return the $credential
	 */
	public function getCredential() {
		return $this->credential;
	}
	
	/**
	 * @return the $courseBegin
	 */
	public function getCourseBegin() {
		return $this->courseBegin;
	}
	
	/**
	 * @return the $courseEnd
	 */
	public function getCourseEnd() {
		return $this->courseEnd;
	}
	
	/**
	 * @return the $time
	 */
	public function getTime() {
		return $this->time;
	}
	
	/**
	 * @return the $unit
	 */
	public function getUnit() {
		return $this->unit;
	}
	
	/**
	 * @return the $salary
	 */
	public function getSalary() {
		return $this->salary;
	}
	
	/**
	 * @return the $new
	 */
	public function getNew() {
		return $this->new;
	}
	
	/**
	 * @return the $approval
	 */
	public function getApproval() {
		return $this->approval;
	}
	
	/**
	 * @param field_type $courseName
	 */
	public function setCourseName($courseName) {
		$this->courseName = $courseName;
	}
	
	/**
	 * @param field_type $department
	 */
	public function setDepartment($department) {
		$this->department = $department;
	}
	
	/**
	 * @param field_type $teacherType
	 */
	public function setTeacherType($teacherType) {
		$this->teacherType = $teacherType;
	}
	
	/**
	 * @param field_type $teacherName
	 */
	public function setTeacherName($teacherName) {
		$this->teacherName = $teacherName;
	}
	
	/**
	 * @param field_type $organization
	 */
	public function setOrganization($organization) {
		$this->organization = $organization;
	}
	
	/**
	 * @param field_type $jobTitle
	 */
	public function setJobTitle($jobTitle) {
		$this->jobTitle = $jobTitle;
	}
	
	/**
	 * @param field_type $credential
	 */
	public function setCredential($credential) {
		$this->credential = $credential;
	}
	
	/**
	 * @param field_type $courseBegin
	 */
	public function setCourseBegin($courseBegin) {
		$this->courseBegin = $courseBegin;
	}
	
	/**
	 * @param field_type $courseEnd
	 */
	public function setCourseEnd($courseEnd) {
		$this->courseEnd = $courseEnd;
	}
	
	/**
	 * @param field_type $time
	 */
	public function setTime($time) {
		$this->time = $time;
	}
	
	/**
	 * @param field_type $unit
	 */
	public function setUnit($unit) {
		$this->unit = $unit;
	}
	
	/**
	 * @param field_type $salary
	 */
	public function setSalary($salary) {
		$this->salary = $salary;
	}
	
	/**
	 * @param field_type $new
	 */
	public function setNew($new) {
		$this->new = $new;
	}
	
	/**
	 * @param field_type $approval
	 */
	public function setApproval($approval) {
		$this->approval = $approval;
	}
	
	public function getFieldAttr() {
		switch ($this->teacherType) {
			case "1" :
				return "工资号";
			case "2" :
				return "身份证号";
			case "3" :
				return "护照号";
			default :
				return "证件号";
		}
	
	}
	
	/**
	 * @return the $salaryStandard
	 */
	public function getSalaryStandard() {
		return $this->salaryStandard;
	}
	
	/**
	 * @param field_type $salaryStandard
	 */
	public function setSalaryStandard($salaryStandard) {
		$this->salaryStandard = $salaryStandard;
	}
	
	public function getWeeks() {
		$begin = strtotime ( $this->courseBegin );
		$end = strtotime ( $this->courseEnd );
		$days = round ( ($end - $begin) / 3600 / 24 );
		$weeks = $days / 7 + ($days % 7 > 0) ? 1 : 0;
		return $weeks;
	
	}
	public function getSalaryStandardAttr() {
		return CourseBean::$standardAttrs [$this->salaryFix];
	}
	public function getSalaryFixAttr(){
		$attr = $this->getSalaryStandardAttr();
		$splits=explode("/", $attr);
		if(isset($splits[0]))
			return $splits[0];
	}
	public static function findById($id) {
		$sql = "select * from course where id='$id'";
		$db = MysqliObj::getInstance ();
		$data = $db->fetch_array ( $sql );
		if (! $data)
			return null;
		return new CourseBean ( $data );
	}
}

?>